account = {"user1": ["pswd", "123456", 5000], "user2": ["pswd", "123456", 5000], "user3": ["pswd", "123456", 5000],
           "user4": ["pswd", "123456", 5000], "user5": ["pswd", "123456", 5000], "user6": ["pswd", "123456", 5000]}


def login(username, direct=False):
    information = account.get(username)
    if direct:
        print('登录成功')
        print(f"电话号码：{information[1]}\n余额：{information[2]}\n")
        return information
    count = 0
    while not information and count < 2:
        count += 1
        information = account.get(input("用户名不存在，请重新输入"))
    password = ""
    if information:
        password = input('密码：')
    for i in range(3):
        if password == information[0]:
            return information
        else:
            password = input('密码错误，请重新输入')
    print('错误已达3次')


print("欢迎进入ATM管理系统")
print("1、使用已有用户名、密码登录")
print("2、注册新用户")
print("3、退出系统")
choice = input("请输入序号选择对应操作：")
while choice not in ["1", "2", "3"]:
    choice = input("输入错误，请重新输入")
information=[]
while choice in ["1", "2"]:
    if choice == "1":
        if not information:
            information = login(input("用户名："))
        if information:
            print("1、存款\n2、取款\n3、转账\n4、返回主界面")
            choice1 = input("请选择操作序号：")
            while choice1 not in ["1", "2", "3", "4"]:
                choice1 = input("输入错误，请重新输入：")
            if choice1 == "1":
                money = input("请输入存款金额：")
                while not money.isdigit():
                    money = input("只能输入数字")
                information[2] += float(money)
                print("存款成功，你的账户余额是{}元".format(information[2]))
            if choice1 == "2":
                money = input("请输入取款金额：")
                while not money.isdigit():
                    money = input("只能输入数字")
                while information[2] < float(money):
                    money = input("余额不足，请重新输入")
                information[2] -= float(money)
                print("取款成功，你的账户余额是{}元".format(information[2]))
            if choice1 == "3":
                target = account.get(input("请输入转账用户名："))
                while not target:
                    target = account.get(input("无此用户，请重新输入："))
                money = input("请输入转账金额")
                while not money.isdigit():
                    money = input("只能输入数字")
                while information[2] < float(money):
                    money = input("余额不足，请重新输入")
                information[2] -= float(money)
                target[2] += float(money)
                print("转账成功，你的账户余额是{}元".format(information[2]))
            if choice1 == "4":
                print("欢迎进入ATM管理系统")
                print("1、使用已有用户名、密码登录")
                print("2、注册新用户")
                print("3、退出系统")
                choice = input("请输入序号选择对应操作：")
                while choice not in ["1", "2", "3"]:
                    choice = input("输入错误，请重新输入")
                information = []
        else:
            print("退出系统")
            choice = "3"
    if choice == "2":
        username = input("用户名")
        while account.get(username):
            print("用户名已存在，请重新输入")
            username = input("用户名")
        password = input("密码")
        while password == "":
            print("密码不能为空")
            password = input("密码")
        tel = input("电话号码")
        while tel == "":
            print("电话号码不能为空")
            tel = input("电话号码")
        account[username] = [password, tel, 5000]
        print("注册新用户成功，请选择下一步操作")
        print("1、自动登录")
        print("3、退出系统")
        choice = input()
        while choice not in ["1", "3"]:
            choice = input("输入错误，请重新输入")
        if choice == "1":
            information=login(username,True)

"""
这次完成的不错，功能均已实现。继续加油努力
"""